<?php
/*=============================================
          Drop-In Photo Gallery

            by Sam Perkins-Harbin
               www.forge22.com
          Last Revision: 22 July, 2005
=============================================*/

$show_folders = 1;     // Set to 1 to show folder list, 0 to turn off
$show_parent = 1;      // Set to 1 to show parent directory link, 0 to turn off

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
	"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Directory Lister</title>
<style type="text/css">

body {text-align: center; font-size: 12px; font-family: verdana; background-color: #eee; color: #000;}
#container {width: 600px; margin: auto; text-align: left;}
h1 {text-align: center; font-family: verdana; font-size: 20px; }
h2, h3 {text-align: left; }

#dirnav {width: 600px; margin: auto; }
#dirnav a:link, #dirnav a:visited {color: #000099; text-decoration: none; }
#dirnav a:hover, #dirnav a:active {color: #fff; background-color: #999; text-decoration: none;}

#links {position: relative; width: 480px; margin: auto;
	overflow: auto; text-align: center;	 }
#links ul {width: 450px; margin: auto; padding: 0; text-align: left;
	list-style-type: none;}
#links li {width: 450px; float: left;
	border-bottom: 1px solid black; }
#links a {display: block; height: 100%; width: 100%; padding: 3px; }
#links a:link, #links a:visited {color: #000099; }
#links a:hover, #links a:active {color: #fff; background-color: #999; }

</style>
</head>
<body>
<div id="container">
<h1>Drop-In File Lister</h1>

<?
$dirlist = dirname($_SERVER['SCRIPT_NAME']);
$d = $_GET['d'];


function dir_list($dir)
{
  global $show_parent, $prev_dir;
  $dlist = array();
    //$hdir = opendir($dir);
    //if (! $hdir)
    //  die('Cannot list files for ' . $dir);
  if ($hdir = opendir($dir))
  {
    while ($obj = readdir($hdir))
      {
        if (((preg_match("/^\./",$obj)==0) && (!eregi('^(.*).[php]$', $obj))) && is_dir($dir.$obj))
          $dlist[] = $obj;
      }
    closedir($hdir);
  }
  asort($dlist);
  echo "<div id='dirnav'>\n<h2>Current Directory: $dir</h2><h3>Directories:</h3>\n";
  if ($show_parent)
    echo "<a href='?d=$prev_dir'>&laquo; BACK</a> | \n";
  foreach ($dlist as $link)
  {
    $link = $d.$link;
    echo "<a href='?d=$dir$link'>$link</a> | \n";
  }
  echo "\n</div>\n";
}

function getfilesize($size)
{
  $units = array(' B', ' KB', ' MB', ' GB', ' TB');
  for ($i = 0; $size > 1024; $i++) { $size /= 1024; }
  return round($size, 2).$units[$i];
}





//---------------------------------------Set which folder we are viewing----------------

if($_GET['d'])
{
  $d = $_GET['d'].'/';
  $dd = 'd='.$_GET['d'].'&'; // for use in passing to URL strings
  $prev_dir = $current_dir;
  $current_dir .= $d;

}
else
  $current_dir = './';

// "./" displays directory this script resides in
$dir = opendir($current_dir);

if ($show_folders)
  dir_list($current_dir);







//-----------------------Print list of files in current dir--------------------------

function file_list($dir)
{
  global $d;
  $dl = array();
  if ($hd = opendir($dir))
  {
    while ($sz = readdir($hd))
      {
        if ((preg_match("/^\./",$sz)==0) && !is_dir($dir.$sz))
          $dl[] = $sz;
      }
    closedir($hd);
  }
  asort($dl);
  echo '<h3>Files:</h3><div id="links"><ul>';
  foreach ($dl as $link)
  {
    echo '<li><a href="'.$d.$link.'">'.$link.'</a></li>';
  }
  echo '</ul></div>';


}


$dir = "./".$d;

file_list($dir);
unset ($dir);
unset ($dl);
?>
<h3>Drop-In Lister by [<a href="http://www.forge22.com">Forge22</a>]</h3>
</div>
</body>
</html>

